import services from '@/services';
const state = {
  menuList: [], //商品分类列表
  productList: [], //商品列表
  cartList: [], //购物车列表
  cartRefresh: true, //刷新购物车
}

const mutations = {
  setMenuList(state, data) {
    state.menuList = data;
  },
  setCartList(state, data) {
    state.cartList = data;
  },
  setCartRefresh(state, data) {
    state.cartRefresh = data;
  },
}

const actions = {
  //商品分类列表
  async menuList(store, params) {
    const {
      data
    } = await services.menu.menuList(params);
    store.commit("setMenuList", data.data);
    return data;
  },
  //商品分类信息
  async menuInfo(store, params) {
    const {
      data
    } = await services.menu.menuInfo(params);
    return data;
  },
  //商品列表
  async productList(store, params) {
    const {
      data
    } = await services.menu.productList(params);
    return data;
  },
  //商品详情
  async productInfo(store, params) {
    const {
      data
    } = await services.menu.productInfo(params);
    return data;
  },
  //获取购物车列表
  async cartList(store, params) {
    const {
      data
    } = await services.menu.cartList(params);
    store.commit('setCartList', data.data); //保存购物车列表
    return data;
  },
  //商品添加到购物车
  async addCart(store, params) {
    const {
      data
    } = await services.menu.addCart(params);
    return data;
  },
  //修改购物车商品属性
  async changeProduct(store, params) {
    const {
      data
    } = await services.menu.changeProduct(params);
    return data;
  },
  //收藏商品
  async proCollection(store, params) {
    const {
      data
    } = await services.menu.proCollection(params);
    return data;
  },
  //商品是否已收藏
  async collectionUp(store, params) {
    const {
      data
    } = await services.menu.collectionUp(params);
    return data;
  },
  //商品评价列表
  async commentList(store, params) {
    const {
      data
    } = await services.menu.commentList(params);
    return data;
  },
}

const getters = {

}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
